<template>
  <div class="btns">
    <Button v-auth="'secondAccomplishTripartiteSign'" color="#6C7DA8" @click="doSecondInterview">二次面试</Button>
  </div>
  <BasicModal :show="show" title="二次面试" width="30%" :widthComfirm="true" @comfirm="comfirm" @closeModal="show = false">
    <template #content>
      <CommonForm :formList="formList" ref="formRef"></CommonForm>
    </template>
  </BasicModal>
</template>

<script setup lang='ts'>
import CommonForm from "@/views/applicationDetails/CommonForm.vue";
import BasicModal from "@/views/ApplicationDetails/Modals/BasicModal.vue"
import { Button } from "@/components/Button";
import { message } from "ant-design-vue";
import { secondInterview, selectUserByRole } from "@/api/application-details/index.ts";
import { comStores } from '@/store/common/comStore';
import type { IndexFormItem } from "@/views/ApplicationDetails/application-type.ts"
import { ref } from "vue"
const store = comStores()
const { userName } = store.userInFor;
const show = ref<boolean>(false)
const getInterviewer = async () => {
  const data = await selectUserByRole("INTERVIEW");
  console.log(data, 'data')
  if (data && data.code == '10000') {
    formList.value[2].options = data.data
  }
}
const formList = ref<IndexFormItem[]>([
  {
    label: "面试类型", name: "interviewType", value: "", component: 'select', options: [
      { label: '线上面试', value: "线上面试" },
      { label: '线下面试', value: "线下面试" },
    ]
  },
  { label: "面试时间", name: "interviewTime", value: "", component: 'datePicker', format: "YYYY-MM-DD HH:mm", showTime: true },
  { label: "面试官", name: "interviewOfficer", value: "", component: 'select', options: [] },
  { label: "备注", name: "remark", value: "", component: 'textarea',required:false },
])

const doSecondInterview = async () => {
  console.log('二次面试', 'secondInterview');
  show.value = true;
  getInterviewer()

}
const formRef = ref<any>(null)
const comfirm = async () => {
  const res = await formRef.value.submitForm();
  if (!res) return;

  const { resumeId, processId } = store.currentResume;
  let param = {
    resumeId,
    processId,
    editStatus: "SECOND",
    operator: userName,
    remark: ""
  }
  res.forEach(el => {
    param[el.name] = el.value
  })
  const data: any = await secondInterview(param);
  if (data && data.code == '10000') {
    store.getResumeInfo(resumeId);
    show.value = false
    message.success("操作成功")
  } else {
    message.error(data.msg)
  }
}

</script>
<style lang="less" scoped>
.btns {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
</style>
